import {post, get} from '@/utils/request'
import config from "@/config";

/** 查询在线用户 */
export function onlineList(param) {
    return post("/api/control/online",param);
}

export function getAdminControl(param) {
    return post("/api/control/queryAdminControlEntity",param);
}


export function queryCacheSystemList(param) {
    return get("/api/control/queryCacheSystemList",param);
}


export function queryRedisKeys(param) {
    return get("/api/control/queryRedisKeys",param);
}


export function getRedisValue(param) {
    return get("/api/control/getRedisValue",param);
}

/** 查询未读 */
export function getAdminControlSse(success,fail) {
    const url = config.baseURL+ "/api/control/getAdminControl?token="+window.localStorage.getItem('token'); //
    let eventSource = new EventSource(url,{
        withCredentials: true,
        encoding: 'UTF-8',
        headers: {
            "Content-Type": "application/json",
            "token": window.localStorage.getItem('token')
        }
    });
    eventSource.onmessage = (event) => {
        if(event.data === '' || event.data === null){
            return;
        }
        const controlEntity = JSON.parse(event.data);
        success(controlEntity);
    };
    eventSource.onerror = (error) => {
        fail();
        console.error('SSE连接失败', error);
        this.eventSource.close(); // 可以在这里处理重连逻辑
    };
}